import { createRouter, createWebHashHistory } from 'vue-router'
import Layout from '@/views/Layout'
// 判断一级、二级路由，头尾 是否有，有就是用的klayout组件 所以就是二级路由
const routes = [
  {
    path: '/',
    component: Layout,
    children: [
      {
        path: '/',
        component: () => import('@/views/Home')
      },
      {
        path: '/cart',
        component: () => import('@/views/Cart')
      },
      // 怎么动态绑定路由 ：id
      {
        path: '/category/:id', component: () => import('@/views/Category')
      },
      {
        path: '/category/sub/:id', component: () => import('@/views/Category/Sub')
      },
      {
        path: '/goods/:id', component: () => import('@/views/Goods/index.vue')
      },
      {
        path: '/login/callback',
        component: () => import('@/views/Login/callback')
      },
      // 结算页面
      {
        path: '/cart',
        component: () => import('@/views/Cart')
      },
      // 订单页
      {
        path: '/settlement',
        component: () => import('@/views/Settlement')
      },
      // 付款也
      {
        path: '/pay',
        component: () => import('@/views/Pay')
      },
      {
        path: '/pay/callback',
        component: () => import('@/views/Pay/callback.vue')
      },
      // 我的
      {
        path: '/member',
        component: () => import('@/views/Member/Layout'),
        children: [
          { path: '', component: () => import('@/views/Member/Home') },
          { path: 'order', component: () => import('@/views/Member/Order') }
        ]

      }
    ]
  },
  // 登录
  {
    path: '/login',
    component: () => import('@/views/Login')
  },
  // 第三方返回
  {
    path: '/login/callback',
    component: () => import('@/views/Login/callback')
  },
  {
    path: '/playground',
    component: () => import('@/views/Playground')
  }
]
// 创建路由实例
const router = createRouter({
  // 使用hash方式实现路由
  history: createWebHashHistory(),
  routes,
  // 刷新行为时，回到顶部
  scrollBehavior: () => ({ x: 0, y: 0 })

})

export default router
